#!/usr/bin/env python3

# Copyright (c) 2020-2021 Fpemud <fpemud@sina.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.


from .._const import Arch, Lang
from .._vm import VmConfig


class Spec:

    archDict = {
        Arch.X86: "x86",
        Arch.X86_64: "amd64",
    }

    langDict = {
        Lang.en_US: "en-US",
        Lang.zh_CN: "zh-CN",
        Lang.zh_TW: "zh-TW",
    }

    localeCodeDict = {
        Lang.en_US: "1033:00000409",
        Lang.zh_CN: "2052:00000804",
        Lang.zh_TW: "1028:00000404",
        # "0409:00020409",
    }

    timezoneDict = {
        Lang.en_US: "Eastern Standard Time",
        Lang.zh_CN: "China Standard Time",
        Lang.zh_TW: "China Standard Time",
        # "W. Europe Standard Time",
    }

    def __init__(self, arch):
        assert isinstance(arch, Arch)
        self._arch = arch

    def getMainDiskSize(self):
        return "20G"

    def getStorageLayoutName(self):
        return "bios-ntfs"

    def getVmConfig(self):
        # win7 does not support UEFI without CSM:
        #   https://forums.mydigitallife.net/threads/tip-windows-7-uefi-install-without-csm.79551
        #   https://forums.mydigitallife.net/threads/uefiseven-easily-boot-windows-7-on-uefi-class-3-devices.82137
        # it seems (through experiment) win7 needs at least 2 CPUs
        # use network_type="none" to eliminate "Set Network Location" dialog, user can still see it after adding network hardware
        if self._arch == Arch.X86:
            return VmConfig(qemu_vm_type="q35",
                            cpu_arch="x86",
                            cpu_number=2,
                            memory_size="2G",
                            bios_type="bios",
                            disk_interface="ide",
                            network_type="none")
        elif self._arch == Arch.X86_64:
            return VmConfig(qemu_vm_type="q35",
                            cpu_arch="amd64",
                            cpu_number=2,
                            memory_size="4G",
                            bios_type="bios",
                            disk_interface="ide",
                            network_type="none")
        else:
            assert False
